package com.huawei.appgallery.forum.user.usercenter.card;

import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.huawei.appgallery.forum.base.card.ForumCard;
import com.huawei.appgallery.forum.base.card.bean.User;
import com.huawei.appgallery.forum.user.api.IUserFollow;
import com.huawei.appgallery.forum.user.api.IUserFollowProtocol;
import com.huawei.appgallery.forum.user.usercenter.bean.ForumUserHeadCardBean;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import huawei.widget.HwButton;
import huawei.widget.HwTextView;
import o.azb;
import o.bqx;
import o.bqy;
import o.brd;
import o.bst;
import o.cbb.b;
import o.cbb.c;
import o.cbb.j;
import o.cdn;
import o.cil;
import o.emz;
import o.epr;
import o.epv;
import o.eqn;
import o.eqq;
import o.equ;
import o.evx;
import o.fho;
import o.fiu;
import o.fjb;
import o.fjo;
import o.fjq;
import o.fjt;

public class ForumUserHeadCard extends ForumCard implements OnClickListener {
    private LinearLayout ʻ;
    private ImageView ʼ;
    private TextView ʽ;
    private ImageView ˊ;
    private HwButton ˊॱ;
    private ImageView ˋ;
    private Handler ˋॱ = new Handler();
    private LinearLayout ˎ;
    private HwTextView ˏ;
    private User ˏॱ;
    private Context ͺ;
    private TextView ॱ;
    private HwTextView ॱˊ;
    private evx ॱˋ;
    private HwTextView ॱॱ;
    private ForumUserHeadCardBean ॱᐝ;
    private HwTextView ᐝ;

    static final class a extends evx {
        private OnClickListener ˎ;

        a(OnClickListener onClickListener) {
            this.ˎ = onClickListener;
        }

        public void ˋ(View view) {
            this.ˎ.onClick(view);
        }
    }

    class d implements Runnable {
        final /* synthetic */ ForumUserHeadCard ˎ;

        private d(ForumUserHeadCard forumUserHeadCard) {
            this.ˎ = forumUserHeadCard;
        }

        public void run() {
            CharSequence nickname = UserSession.getInstance().getNickname();
            if (!TextUtils.isEmpty(nickname)) {
                this.ˎ.ˏ.setVisibility(0);
                this.ˎ.ˏ.setText(nickname);
            }
        }
    }

    public ForumUserHeadCard(Context context) {
        super(context);
        this.ͺ = context;
        this.ॱˋ = new a(this);
    }

    public View ˋ(LayoutInflater layoutInflater) {
        View inflate = layoutInflater.inflate(o.cbb.d.ˏ, null);
        this.ˋ = (ImageView) inflate.findViewById(b.ॱʻ);
        this.ˏ = (HwTextView) inflate.findViewById(b.ᶥ);
        this.ˊ = (ImageView) inflate.findViewById(b.ॱʼ);
        this.ॱ = (TextView) inflate.findViewById(b.ˋॱ);
        this.ˎ = (LinearLayout) inflate.findViewById(b.ॱᐝ);
        this.ʼ = (ImageView) inflate.findViewById(b.ॱͺ);
        this.ʽ = (TextView) inflate.findViewById(b.ᐨ);
        this.ʻ = (LinearLayout) inflate.findViewById(b.ᐝᐝ);
        this.ʻ.setOnClickListener(this.ॱˋ);
        this.ᐝ = (HwTextView) inflate.findViewById(b.ʾ);
        this.ॱˊ = (HwTextView) inflate.findViewById(b.ꓸ);
        this.ॱॱ = (HwTextView) inflate.findViewById(b.ᐝॱ);
        this.ˊॱ = (HwButton) inflate.findViewById(b.ˋʼ);
        this.ˊॱ.setOnClickListener(this.ॱˋ);
        ((LinearLayout) inflate.findViewById(b.ʿ)).setOnClickListener(this.ॱˋ);
        ((LinearLayout) inflate.findViewById(b.ʽॱ)).setOnClickListener(this.ॱˋ);
        ॱ((ImageView) inflate.findViewById(b.ˉॱ));
        View view = (LinearLayout) inflate.findViewById(b.ˊʼ);
        azb.ˋ(view);
        ॱ(view);
        return inflate;
    }

    private void ॱ(ImageView imageView) {
        int ˎ = epv.ˎ(this.ͺ);
        LayoutParams layoutParams = imageView.getLayoutParams();
        if (cdn.ॱॱ()) {
            layoutParams.height = (int) (((((float) ˎ) * 9.0f) / 21.0f) * 0.52f);
        } else {
            layoutParams.height = (ˎ * 9) / 21;
        }
        imageView.setLayoutParams(layoutParams);
    }

    private void ॱ(View view) {
        int ˏ = epv.ˏ();
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
        layoutParams.topMargin = epv.ˋ(this.ͺ, 24) + ˏ;
        if (epr.ˎ().ॱॱ()) {
            layoutParams.topMargin = ˏ + epv.ˋ(this.ͺ, 56);
        }
        view.setLayoutParams(layoutParams);
    }

    private void ˏ(TextView textView) {
        int ॱ = (azb.ॱ(this.ͺ) - epv.ˋ(this.ͺ, 100)) / 2;
        if (ॱ > 0) {
            textView.setMaxWidth(ॱ);
        }
    }

    public void ˋ(CardBean cardBean) {
        if (cardBean instanceof ForumUserHeadCardBean) {
            this.ॱᐝ = (ForumUserHeadCardBean) cardBean;
            this.ˏॱ = this.ॱᐝ.ˊ();
            if (this.ˏॱ != null) {
                equ.ˊ(this.ˋ, this.ˏॱ.ˎ(), "head_default_icon");
                Object ˋ = this.ˏॱ.ˋ();
                if (TextUtils.isEmpty(ˋ)) {
                    this.ˏ.setVisibility(8);
                } else {
                    ˎ(this.ˏ, 0, ˋ);
                }
                ʽ();
                if (TextUtils.isEmpty(this.ˏॱ.ˏ())) {
                    this.ˎ.setVisibility(8);
                    ˎ(this.ॱ, 8, null);
                } else {
                    this.ˎ.setVisibility(0);
                    ˎ(this.ॱ, 0, this.ˏॱ.ˏ());
                }
                if (this.ˏॱ.ʻ()) {
                    ˊ(this.ˊ, 0, o.cbb.a.ॱ);
                } else if (this.ˏॱ.ᐝ()) {
                    ˊ(this.ˊ, 0, o.cbb.a.ˎ);
                } else {
                    ˊ(this.ˊ, 8, o.cbb.a.ˎ);
                }
                ˏ(this.ˏॱ.ˋॱ());
                if (this.ʻ.getVisibility() == 0 && this.ˎ.getVisibility() == 0) {
                    ˏ(this.ʽ);
                }
                ˎ(this.ᐝ, 0, bst.ॱ(this.ͺ, (long) this.ˏॱ.ˏॱ()));
                ˎ(this.ॱॱ, 0, bst.ॱ(this.ͺ, (long) this.ˏॱ.ˊॱ()));
                ˎ(this.ॱˊ, 0, bst.ॱ(this.ͺ, (long) this.ˏॱ.ॱˊ()));
                if (this.ˏॱ.ʼ()) {
                    this.ˊॱ.setVisibility(8);
                    return;
                }
                this.ˊॱ.setVisibility(0);
                ॱ(this.ˏॱ.ʻॱ());
            }
        }
    }

    public void ॱ(CardBean cardBean) {
        if (cardBean instanceof ForumUserHeadCardBean) {
            this.ॱᐝ = (ForumUserHeadCardBean) cardBean;
            this.ˏॱ = this.ॱᐝ.ˊ();
            if (this.ˏॱ != null) {
                ˎ(this.ᐝ, 0, bst.ॱ(this.ͺ, (long) this.ˏॱ.ˏॱ()));
                ˎ(this.ॱॱ, 0, bst.ॱ(this.ͺ, (long) this.ˏॱ.ˊॱ()));
                ॱ(this.ˏॱ.ʻॱ());
            }
        }
    }

    public void onClick(View view) {
        if (view.getId() == b.ˋʼ) {
            ᐝ();
        } else if (view.getId() == b.ʿ) {
            ʼ();
        } else if (view.getId() == b.ʽॱ) {
            ʻ();
        } else if (view.getId() == b.ᐝᐝ) {
            ॱॱ();
        }
    }

    private void ᐝ() {
        if (this.ॱᐝ == null || this.ˏॱ == null) {
            bqx.ॱ("ForumUserHeadCard", "followAction failed: the headCardBean or user is null");
            return;
        }
        final int i = this.ˏॱ.ʻॱ() == 0 ? 0 : 1;
        ((IUserFollow) fho.ˏ().ˋ("User").ॱ(IUserFollow.class)).ॱ(this.ͺ, this.ˏॱ, i).ˋ(fjt.ˎ(), new fjq<IUserFollow.b>(this) {
            final /* synthetic */ ForumUserHeadCard ˎ;

            public void onComplete(fjo<IUserFollow.b> o_fjo_com_huawei_appgallery_forum_user_api_IUserFollow_b) {
                IUserFollow.b bVar = (IUserFollow.b) o_fjo_com_huawei_appgallery_forum_user_api_IUserFollow_b.ॱ();
                if (o_fjo_com_huawei_appgallery_forum_user_api_IUserFollow_b.ˊ() && bVar.ˏ() == 0) {
                    int ˋ = ((IUserFollow.b) o_fjo_com_huawei_appgallery_forum_user_api_IUserFollow_b.ॱ()).ˋ();
                    if (ˋ != this.ˎ.ˏॱ.ʻॱ()) {
                        if (ˋ == 0) {
                            this.ˎ.ˏॱ.ᐝ(this.ˎ.ˏॱ.ˊॱ() - 1);
                        } else {
                            this.ˎ.ˏॱ.ᐝ(this.ˎ.ˏॱ.ˊॱ() + 1);
                        }
                        this.ˎ.ˏॱ.ˎ(ˋ);
                        this.ˎ.ॱ(this.ˎ.ॱᐝ);
                        brd.ॱ.ˋ(bqy.ˋ().ˎ(this.ˎ.ͺ), bqy.ˋ().ˎ(), this.ˎ.ॱᐝ.ॱˈ(), "HISPAGE", i == 0 ? 1 : 0);
                    }
                }
            }
        });
    }

    private void ʼ() {
        if (this.ॱᐝ == null || this.ॱᐝ.ˊ() == null) {
            bqx.ॱ("ForumUserHeadCard", "goFollowDetailPage failed: the headCardBean or user is null");
            return;
        }
        cil.ˋ(this.ͺ, new o.cim.a().ˊ(this.ॱᐝ.ʽ()).ˋ());
        fjb ˎ = fho.ˏ().ˋ("User").ˎ("forum.user.follow");
        IUserFollowProtocol iUserFollowProtocol = (IUserFollowProtocol) ˎ.ˊ();
        iUserFollowProtocol.setUri(this.ॱᐝ.ʽ());
        iUserFollowProtocol.setDomainId(this.ॱᐝ.ॱ());
        iUserFollowProtocol.setUserType(this.ॱᐝ.ˊ().ˊ());
        fiu.ˊ().ˏ(this.ͺ, ˎ);
    }

    private void ʻ() {
        if (this.ॱᐝ == null) {
            bqx.ॱ("ForumUserHeadCard", "goFansDetailPage failed: the headCardBean is null or has deleted");
            return;
        }
        cil.ˋ(this.ͺ, new o.cim.a().ˊ(this.ॱᐝ.ʽ()).ˋ());
        fjb ˎ = fho.ˏ().ˋ("User").ˎ("forum.user.follow");
        IUserFollowProtocol iUserFollowProtocol = (IUserFollowProtocol) ˎ.ˊ();
        iUserFollowProtocol.setUri(this.ॱᐝ.ʽ());
        iUserFollowProtocol.setDomainId(this.ॱᐝ.ॱ());
        iUserFollowProtocol.setFocus(1);
        fiu.ˊ().ˏ(this.ͺ, ˎ);
    }

    private void ॱॱ() {
        if (this.ˏॱ == null) {
            bqx.ॱ("ForumUserHeadCard", "goLevelPage failed: the user is null or has deleted");
            return;
        }
        Object ͺ = this.ˏॱ.ͺ();
        cil.ˋ(this.ͺ, new o.cim.a().ˊ(ͺ).ˋ());
        if (!TextUtils.isEmpty(ͺ)) {
            emz.ˊ(this.ͺ, ͺ);
        }
    }

    private void ʽ() {
        if (this.ˏॱ != null && this.ˏॱ.ʼ()) {
            eqq.ˋ().ˎ("ForumUserHeadCard", new eqn(this) {
                final /* synthetic */ ForumUserHeadCard ॱ;

                {
                    this.ॱ = r1;
                }

                public void onResult(int i) {
                    if (i == 202) {
                        this.ॱ.ˋॱ.post(new d());
                    }
                }
            });
        }
    }

    private void ˏ(int i) {
        if (i <= 0 || i >= 21) {
            this.ʻ.setVisibility(8);
            ˎ(this.ʽ, 8, null);
            ˊ(this.ʼ, 8, o.cbb.a.ʼ);
            return;
        }
        this.ʻ.setVisibility(0);
        ˎ(this.ʽ, 0, this.ͺ.getResources().getString(j.ʿ, new Object[]{Integer.valueOf(i)}));
        ˊ(this.ʼ, 0, this.ͺ.getResources().getIdentifier("ic_grade_small_" + i, "drawable", this.ͺ.getPackageName()));
    }

    private void ॱ(int i) {
        if (i == 2) {
            this.ˊॱ.setText(j.ͺ);
            this.ˊॱ.setTextColor(this.ͺ.getResources().getColor(c.ˏ));
        } else if (i == 1) {
            this.ˊॱ.setText(j.ˊॱ);
            this.ˊॱ.setTextColor(this.ͺ.getResources().getColor(c.ˏ));
        } else {
            this.ˊॱ.setText(j.ʻॱ);
            this.ˊॱ.setTextColor(this.ͺ.getResources().getColor(c.ˊ));
        }
    }

    public void ˎ(String str, String str2) {
        if (this.ॱᐝ != null) {
            User ˊ = this.ॱᐝ.ˊ();
            if (ˊ != null) {
                ˊ.ˎ(str2);
                ˊ.ˋ(str);
            }
        }
        equ.ˊ(this.ˋ, str, "head_default_icon");
        if (TextUtils.isEmpty(str2)) {
            this.ˏ.setVisibility(8);
        } else {
            ˎ(this.ˏ, 0, str2);
        }
    }

    private void ˎ(TextView textView, int i, String str) {
        if (textView != null) {
            textView.setVisibility(i);
            textView.setText(str);
        }
    }

    private void ˊ(ImageView imageView, int i, int i2) {
        if (imageView != null) {
            imageView.setVisibility(i);
            imageView.setImageResource(i2);
        }
    }

    public void ˎ() {
        eqq.ˋ().ˊ("ForumUserHeadCard");
    }
}
